package com.webapp.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import com.webapp.util.DateUtil;


@SuppressWarnings("serial")
@MappedSuperclass
public class BaseEntity implements Serializable {
	
	private Long id;
	private Date createdAt;
	private Date updatedAt;
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    @Transient
    public String getCreatedAtString() {
    	return DateUtil.formatDate(createdAt, DateUtil.FULL_DATE_TIME_FORMAT);
    }

	public Date getCreatedAt() {
		return createdAt;
	}
	
	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	@Transient
	public String getUpdatedAtString() {
		return DateUtil.formatDate(updatedAt, DateUtil.FULL_DATE_TIME_FORMAT);
	}
	
	public Date getUpdatedAt() {
		return updatedAt;
	}
	

	public void setUpdatedAt(Date updatedAt) {
		this.updatedAt = updatedAt;
	}

	public boolean exist() {
		return id != null && id > 0;
	}

}
